import 'package:flutter/material.dart';
import 'package:flutter_lib/utils/DpUtils.dart';
import 'package:flutter_my_web/bean/response/get_music_tag_response.dart';
import 'package:flutter_my_web/pages/music/music_menu_tab_bar_view_widget.dart';
import 'package:flutter_my_web/widget/TextWidget.dart';
import 'package:get/get.dart';

import 'music_menu_tab_widget.dart';

bool isHaveMusicMenuPop = false;
class MusicMenuPopRoute extends PopupRoute {
  Widget widget;


  Curve? curve;

  MusicMenuPopRoute(this.widget,):super(settings: RouteSettings(name: "MusicMenuPopRoute"));

  final Duration _duration = Duration(milliseconds: 200);

  ///弹出蒙层的颜色，null则为透明
  @override
  Color? get barrierColor => null;

  @override
  bool get barrierDismissible => true;

  @override
  String? get barrierLabel => null;
  @override
  void dispose() {
    print("dispose");
    super.dispose();
  }
  @override
  bool didPop(result) {
    print("didPop");
    isHaveMusicMenuPop = false;
    return super.didPop(result);
  }
  @override
  Widget buildPage(BuildContext context, Animation<double> animation,
      Animation<double> secondaryAnimation) {
    return widget;
  }

  @override
  Duration get transitionDuration => _duration;
}

void showMusicMenuDialog(BuildContext context,List<GetMusicTagBean> tabs) {
  if(isHaveMusicMenuPop){
    Navigator.pop(context);
  }
  Navigator.push(context, MusicMenuPopRoute(MusicMenuWidget(tabs)));
  isHaveMusicMenuPop = true;
  print("showMusicMenuDialog");
}

class MusicMenuWidget extends StatefulWidget {
  List<GetMusicTagBean> tabs;

  MusicMenuWidget(this.tabs);

  @override
  State<MusicMenuWidget> createState() => _MusicMenuWidgetState();
}

class _MusicMenuWidgetState extends State<MusicMenuWidget>
    with SingleTickerProviderStateMixin {
  late TabController tabController;

  @override
  void initState() {
    super.initState();
    tabController = TabController(length: widget.tabs.length, vsync: this);
  }

  @override
  void dispose() {
    super.dispose();
    tabController.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Stack(
      children: [
        Positioned(
          bottom: 50.0.hDp,right: 0,
          child: Container(
            color: Colors.black38,
              width: Get.width / 2,
              height: Get.height / 2,
              child: Material(
                color: Colors.transparent,
                child: Column(
                  children: [
                    SizedBox(
                      height: 30.0.hDp,
                      child: TabBar(
                        isScrollable: true,
                        controller: tabController,
                        tabs:
                            widget.tabs.map((e) => music_menu_tab_bar_widget(e)).toList(),
                      ),
                    ),
                    Expanded(
                      child: TabBarView(
                          children: widget.tabs
                              .map((e) => music_menu_tab_bar_view_widget(e))
                              .toList(),
                          controller: tabController),
                    )
                  ],
                ),
              )),
        ),
      ],
    );
  }
}
